<?php
/**
 * 商会通讯录模块定义
 *
 * @author zh0537cn
 * @url http://s.we7.cc/
 */
defined('IN_IA') or exit('Access Denied');

global $_W, $_GPC;

load()->func('tpl');

$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';

$opp = 'tabbar';

$uniacid = $_W['uniacid'];

load()->model('module');
load()->model('wxapp');

$dos = array('entrance_link');
$do = in_array($do, $dos) ? $do : 'entrance_link';

$_W['page']['title'] = '入口页面 - 小程序 - 管理';

$version_id = intval($_GPC['version_id']);
$wxapp_info = wxapp_fetch($_W['uniacid']);
if (!empty($version_id)) {
	$version_info = wxapp_version($version_id);
}

if ($do == 'entrance_link') {
	$wxapp_modules = pdo_getcolumn('wxapp_versions', array('id' => $version_id), 'modules');
	$module_info = array();
	if (!empty($wxapp_modules)) {
		$module_info = iunserializer($wxapp_modules);
		$module_info = pdo_getall('modules_bindings', array('module' => array_keys($module_info), 'entry' => 'page'));
	}
}
$lid = $_GPC['lid'];

if ($operation == 'display') {
	
$tabbar = pdo_fetch("SELECT * FROM " . tablename('bbyscm_card_tabbar') . ' where `uniacid`=:uniacid limit 1', array(':uniacid' => $uniacid));

//$tabbar_list = pdo_getall("bbyscm_card_tabbar_list", array("uniacid" => $uniacid));

$tabbar_list = pdo_fetchall('SELECT *  FROM ' . tablename('bbyscm_card_tabbar_list') . ' WHERE uniacid ='. $uniacid.' ORDER BY sort ASC');

if (!empty($tabbar_list)) {
	
            foreach ($tabbar_list as $key => $value) {
				
            $tabbar_list[$key]['iconPath'] = tomedia($value['iconPath']);
			
			$tabbar_list[$key]['selectedIconPath'] = tomedia($value['selectedIconPath']);
           
        }
     }

if (checksubmit('submit')) {
	
    $data['color'] = $_GPC['color'];
    $data['selectedColor'] = $_GPC['selectedColor'];
    $data['backgroundColor'] = $_GPC['backgroundColor'];
    $data['borderStyle'] = $_GPC['borderStyle'];
	$data['tabbar_key'] = $_GPC['tabbar_key'];
	
	if (empty($tabbar)) {
	 
        $data['uniacid'] = $uniacid;
		
        pdo_insert('bbyscm_card_tabbar', $data);
		
		message('参数设置成功！', $this->createWebUrl('tabbar', array('op' => 'display')), 'success');
		
    } else {
		
        pdo_update('bbyscm_card_tabbar', $data, array('uniacid' => $uniacid));
		
		message('更新参数设置成功！', $this->createWebUrl('tabbar', array('op' => 'display')), 'success');
    }
	}
 } elseif ($operation == 'post') {
	if (checksubmit('submit')) {
	$datal['pagePath'] = $_GPC['pagePath'];
	$datal['text'] = $_GPC['text'];
	$datal['wx_key'] = $_GPC['wx_key'];
	$datal['wx_appid'] = $_GPC['wx_appid'];
    $datal['iconPath'] = $_GPC['iconPath'];
	$datal['selectedIconPath'] = $_GPC['selectedIconPath'];
	$datal['sort'] = $_GPC['sort'];
 
 if (empty($lid)) {
	 
        $datal['uniacid'] = $uniacid;
		
        pdo_insert('bbyscm_card_tabbar_list', $datal);
		
		message('添加成功！', $this->createWebUrl('tabbar', array('op' => 'display')), 'success');
		
    } else {
		
        pdo_update('bbyscm_card_tabbar_list', $datal, array('lid' => $_GPC['lid']));
		
		message('编辑参数设置成功！', $this->createWebUrl('tabbar', array('op' => 'display')), 'success');
	}
	}
    $banner = pdo_fetch("select * from " . tablename('bbyscm_card_tabbar_list') . " where lid=:lid and uniacid=:uniacid limit 1", array(":lid" => $lid, ":uniacid" => $_W['uniacid']));
	
  } elseif ($operation == 'delete') {
			
			$banner2 = pdo_fetch("SELECT lid FROM " . tablename('bbyscm_card_tabbar_list') . " WHERE lid = '$lid' AND uniacid=" . $_W['uniacid'] . "");
			
			if (empty($banner2)) {
				message('抱歉，不存在或是已经被删除！', $this->createWebUrl('tabbar', array('op' => 'display')), 'error');
			}
			pdo_delete('bbyscm_card_tabbar_list', array('lid' => $lid));
			
			message('删除成功！', $this->createWebUrl('tabbar', array('op' => 'display')), 'success');
			
		} 

include $this->template('web/tabbar');
